package 比屋作业.day13;

import java.util.concurrent.Callable;

public class D13_2{
    public static void main(String[] args) {
        Dog dog1=new Dog("旺财");
        Dog dog2=new Dog("旺财");
        dog1.sound();
        System.out.println(dog1);
        dog2.sound();
        System.out.println(dog2);
        System.out.println(dog1.equals(dog2));
        Cat cat1=new Cat("小黑");
        Cat cat2=new Cat("小白");
        System.out.println(cat1);
        System.out.println(cat2);
        cat1.sound();
        cat2.sound();
        System.out.println(cat1.equals(cat2));
    }
}
abstract class Animal{
    public abstract void sound();
}
class Dog extends Animal{
    private String name;
    public Dog(String name){
        this.name=name;
    }

    @Override
    public void sound() {
        System.out.println("汪汪汪....");
    }

    @Override
    public String toString() {
        return "名为"+name+"的小狗";
    }

    @Override
    public boolean equals(Object obj) {
        Dog dog=(Dog) obj;
        return this.name.equals(dog.name);
    }
}
class Cat extends Animal{
    private String name;
    public Cat(String name){
        this.name=name;
    }
    @Override
    public void sound() {
        System.out.println("喵喵喵.....");
    }
    @Override
    public String toString() {
        return "名为"+name+"的小猫";
    }
    @Override
    public boolean equals(Object obj) {
        Cat cat=(Cat) obj;
        return this.name.equals(cat.name);
    }
}